package com.ericsson.enap.modules.procLog.task;

import com.ericsson.common.quartz.task.ManualTask;
import com.ericsson.common.util.LogFileName;
import com.ericsson.common.util.LoggerUtils;
import com.ericsson.enap.modules.procLog.constant.ProcConstant;
import com.ericsson.enap.modules.procLog.service.ProcLogService;
import com.ericsson.enap.modules.sys.entity.EnipNetelement;
import com.ericsson.enap.modules.sys.entity.EpcDict;
import com.ericsson.enap.modules.sys.service.EpcDictService;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @description: procLog主任务
 * @author: wangjingshi
 * @create: 2021-05-06 09:32
 */
@Component
public class ProcLogTask implements ManualTask  {

    private Logger log = LoggerUtils.Logger(LogFileName.ProcLogJob);

    @Autowired
    private ProcLogService procLogService;
    @Autowired
    private EpcDictService epcDictService;
    @Value("${collectorIp}")
    private String collectorIp;

    @Override
    public void execute() {
        long startTime = new Date().getTime();
        log.info("===== do ProcLogTask start =====: "+startTime);
        String procPath = epcDictService.selectEpcDict(new EpcDict(ProcConstant.ProcLogPath)).getKeyValue();
        String delay = epcDictService.selectEpcDict(new EpcDict(ProcConstant.ProcDelay)).getKeyValue();
        //1、从EDA网元上下载tar文件并解压tar文件
        List<EnipNetelement> list = procLogService.downLoadProcTar(collectorIp,procPath,delay);
        //2、按照网元拆分线程,遍历目录,继续解压缩gz文件,再解析csv
        procLogService.unzgAndAnalysis(list,procPath);


    }
}
